package com.migraine.service.impl;

import com.migraine.mapper.MessageMapper;
import com.migraine.model.Message;
import com.migraine.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    MessageMapper messageMapper;

    @Override
    public boolean insertMessage(int id, String sender, String receiver, String msg, Date date) {
        return messageMapper.insertMessage(id, sender, receiver, msg, date);
    }

    @Override
    public boolean deleteMessage(int id) {
        // 删除成功返回true,没有此id或者删除失败返回false
        return messageMapper.deleteMessageById(id);
    }

    @Override
    public List<Integer> getMessageByName(String receiver) {
        // 返回receiver收到的所有留言id，没有查到就返回一个空数组
        return messageMapper.getMessageByName(receiver);
    }

    @Override
    public List<Integer> getAllId() {
        // 返回所有的messageid,没有的话返回一个空数组
        return messageMapper.getAllId();
    }

    @Override
    public List<Message> getMessageById(String id) {
        return  messageMapper.selectByPrimaryKey(id);
    }

    @Override
    public Message selectMessageById(int id) {
        return messageMapper.selectMessagebyId(id);
    }
}
